﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class BabysitterRegistration4 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }

    protected void sittersform3_Click(object sender, EventArgs e)
    {
        int bsID = Convert.ToInt32(Request.QueryString["bsID"]);
        int acctID = Convert.ToInt32(Request.QueryString["bAcctID"]);
        //int bsID = 12;

        string connStr = ConfigurationManager.ConnectionStrings["CSConn"].ToString();
        SqlConnection conn = new SqlConnection(connStr);

        SqlCommand cmd1 = new SqlCommand("BabySittersRegistration4_con", conn);
        cmd1.CommandType = CommandType.StoredProcedure;

        cmd1.Parameters.Add(new SqlParameter("@bsID", bsID));
        cmd1.Parameters.Add(new SqlParameter("@daycaretwosix", conditions2(CheckBox4)));
        cmd1.Parameters.Add(new SqlParameter("@daycaresixtwelve", conditions2(CheckBox5)));
        cmd1.Parameters.Add(new SqlParameter("@nightcare", conditions2(CheckBox2)));
        cmd1.Parameters.Add(new SqlParameter("@workoffsched", conditions2(notify)));
        cmd1.Parameters.Add(new SqlParameter("@hrsweek", int.Parse(DropDownList1.SelectedValue)));
        cmd1.Parameters.Add(new SqlParameter("@hrsday", int.Parse(DropDownList2.SelectedValue)));

        conn.Open();
        cmd1.ExecuteNonQuery();
        conn.Close();

        for (int i = 0; i < bSchedule.Items.Count; i++)
        {
            if (bSchedule.Items[i].Selected)
            {
                string[] a = bSchedule.Items[i].Value.Split(',');
                int dhID = int.Parse(a[0]);
                if (a[1] == "1")
                {
                    helper1(bsID, dhID, "Sunday");
                }
                if (a[1] == "2")
                {
                    helper1(bsID, dhID, "Monday");
                }
                if (a[1] == "3")
                {
                    helper1(bsID, dhID, "Tuesday");
                }
                if (a[1] == "4")
                {
                    helper1(bsID, dhID, "Wednesday");
                }
                if (a[1] == "5")
                {
                    helper1(bsID, dhID, "Thursday");
                }
                if (a[1] == "6")
                {
                    helper1(bsID, dhID, "Friday");
                }
                if (a[1] == "7")
                {
                    helper1(bsID, dhID, "Saturday");
                }
            }
        }

        Response.Redirect("http://www.cairositters.com/GUI/Pages/BabysitterRegistration5.aspx?bsID=" + bsID + "&bAcctID=" + acctID);
        //Response.Redirect("http://localhost:60070/CSWebSite_v1.0/GUI/Pages/BabysitterRegistration5.aspx?bsID=" + bsID + "&bAcctID=" + acctID);
    }
    
    protected bool conditions2(CheckBox c)
    {
        bool b;
        if (c.Checked == true)
            b = true;
        else
            b = false;

        return b;
    }

    protected void helper1(int bsID, int dhID, string day)
    {
        string connStr = ConfigurationManager.ConnectionStrings["CSConn"].ToString();
        SqlConnection conn = new SqlConnection(connStr);

        int bssID = 0;
        SqlCommand cmd1 = new SqlCommand("ScheduleDay", conn);
        cmd1.CommandType = CommandType.StoredProcedure;

        cmd1.Parameters.Add(new SqlParameter("@bsID", bsID));
        cmd1.Parameters.Add(new SqlParameter("@day", day));

        conn.Open();
        bssID = Convert.ToInt32((decimal)cmd1.ExecuteScalar());
        conn.Close(); 
        
        SqlCommand cmd2 = new SqlCommand("ScheduleHour", conn);
        cmd2.CommandType = CommandType.StoredProcedure;

        cmd2.Parameters.Add(new SqlParameter("@bssID", bssID));
        cmd2.Parameters.Add(new SqlParameter("@dhID", dhID));

        conn.Open();
        cmd2.ExecuteNonQuery();
        conn.Close();
    }

    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        if (CheckBox1.Checked == true)
        {
            CheckBox4.Enabled = true;
            CheckBox5.Enabled = true;
        }
        else
        {
            CheckBox4.Enabled = false;
            CheckBox5.Enabled = false;
        }
    }
}